"""Constants used in the interface between dingo-vis and Dingo tools, plugins and models.

Copyright (C) Sarah Mount, 2008.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have rceeived a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""

__author__ = 'Sarah Mount <s.mount@wlv.ac.uk>'
__date__ = 'April 2008'

import socket

### Publisher / subscriber categories
### Note that using events / handlers runs like a drain. So don't.
RADIO_TOPIC = 'radiomsg'
"""@var: Pub/sub topic to inform GUI that a radio message has been sent."""
NEW_AVATAR_TOPIC = 'newsensoravatar'
"""@var: Pub/sub topic to inform GUI that a sensor wishes create an avatar for itself."""
COLOUR_TOPIC = 'setcolour'
"""@var: Pub/sub topic to inform GUI that a sensor wishes to change it's avatar colour."""
SHAPE_TOPIC = 'setshape'
"""@var: Pub/sub topic to inform GUI that a sensor wishes to change it's avatar shape."""
MOVE_TOPIC = 'moveavatar'
"""@var: Pub/sub topic to inform GUI that a sensor wishes to move it's avatar."""
ATTACH_TOPIC = 'attachgui'
"""@var: Pub/sub topic to inform sensors that a GUI has been attached to the running sensor network."""
DETACH_TOPIC = 'detachgui'
"""@var: Pub/sub topic to inform sensors that a GUI has been detached from the running sensor network."""


def debug(msg):
    """Send message to the debug plugin.

    See L{Dingo.plugins.debug}
    """
    debugsock.sendto(msg, (host, DEBUG_PORT))

def adcreport(data):
    """Send data gathered by a real or virtual ADC to the ADC plugin.

    See L{Dingo.plugins.adcevents}
    """
    adcsock.sendto(data, (host, DEBUG_PORT))


### Sockets
host = socket.gethostname()
"""@var: localhost. FIXME: Will only work in simulation!"""
DEBUG_PORT = 10000
"""@var: Socket port for debug plugin. See L{Dingo.plugins.debug}"""
ADC_PORT = 10001
"""@var: Socket port for ADC events plugin. See L{Dingo.plugins.adcevents}"""
BUFFSIZE = 1024
"""@var: Default buffer size for reading from sockets."""

debugsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
"""@var: Socket used by the debug plugin. See L{Dingo.plugins.debug}"""
adcsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
"""@var: Socket used by the ADC plugin. See L{Dingo.plugins.adcevents}"""
